import logging

from eshop.lib.base import *
#from model import *

log = logging.getLogger(__name__)

class BrandController(BaseController):

  
    def add(self):
        return render('/catalog/brand_add.mako')
    
    def delete(self, id):
        model.Brand.q.get(id).delete()
        redirect_to(action='index', id=None)
    
    def edit (self, id):
        c.brand = model.Brand.q.get(id)
        return render('/catalog/brand_edit.mako')

    def index(self):
        c.brands = model.Brand.q.all()
        return render('/catalog/brand_list.mako')
    
    def view (self, id=None):
        c.brand = model.Brand.q.get(id)
        return render('/catalog/brand_view.mako')
    
    def save_edit(self, id):
        brand = model.Brand.q.get(id)
        brand.name = request.params.get('name')
        redirect_to(action='index')
        
    def save_add(self):
        brand = model.Brand(\
            name=request.params.get('name'))
        redirect_to(action='index')
    
